package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.object.pojo.AppointMentLog;
import com.tbit.uqbike.object.pojo.User;
import com.tbit.uqbike.service.business.AppointMentLogService;
import com.tbit.uqbike.service.business.AppointMentService;
import com.tbit.uqbike.webmanager.dao.core.AccountDao;
import com.tbit.uqbike.webmanager.dao.core.UserDao;
import com.tbit.uqbike.webmanager.dao.log.AppointMentLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: chen
 * @Description: 预约日志
 * @Date: 创建于 17:19 2020/8/13
 */
@Service
public class AppointMentLogServiceImpl implements AppointMentLogService {
    @Autowired
    private AppointMentLogDao appointMentLogDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private AccountDao accountDao;
    @Autowired
    private AppointMentService appointMentService;

    @Override
    public List<AppointMentLog> queryPage(String phone, Integer areaId, String machineNO, String userCode,
                                          Integer pageNO, Integer rowCount) {
        Map<String, Object> params = appointMentService.getUserByPhoneAndAreaId(phone, areaId);
        if (null != phone && null == params.get("userId")) {
            return null;
        }
        params.put("machineNO", machineNO);
        params.put("userCode", userCode);
        params.put("start", (pageNO - 1) * rowCount);
        params.put("rowCount", rowCount);
        List<AppointMentLog> appointMentLogs = appointMentLogDao.queryPage(params);
        if (appointMentLogs.size() != 0 || null != appointMentLogs) {
            for (AppointMentLog appointMentLog : appointMentLogs) {
                User user = userDao.getByUserId(appointMentLog.getUserId());
                appointMentLog.setUserName(user.getName());
                appointMentLog.setPhone(user.getPhone());
                appointMentLog.setAreaName(accountDao.getByAccountId(appointMentLog.getAccountId()).getName());
            }
        }
        return appointMentLogs;
    }

    @Override
    public Integer queryCount(String phone, Integer areaId, String machineNO, String userCode) {
        Map<String, Object> params = appointMentService.getUserByPhoneAndAreaId(phone, areaId);
        params.put("machineNO", machineNO);
        params.put("userCode", userCode);
        return appointMentLogDao.queryCount(params);
    }
}
